package cn.lutu.lutu.controller;

import cn.lutu.lutu.mapper.HotelsMapper;
import cn.lutu.lutu.pojo.dto.HotelDTO;
import cn.lutu.lutu.pojo.dto.RoomDTO;
import cn.lutu.lutu.pojo.entity.Hotel;
import cn.lutu.lutu.pojo.entity.Room;
import cn.lutu.lutu.pojo.vo.HotelVO;
import cn.lutu.lutu.pojo.vo.RoomVO;
import cn.lutu.lutu.pojo.vo.UserVO;
import cn.lutu.lutu.response.ResultVO;
import cn.lutu.lutu.response.StatusCode;
import cn.lutu.lutu.service.HotelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "酒店产品模块")
@RestController
@RequestMapping("/v1/hotels")
public class HotelController {
    @Autowired
    HotelService hotelService;

    @ApiOperation(value = "添加酒店产品功能")
    @PostMapping("add")
    public ResultVO insert(@RequestBody HotelDTO hotelDTO) {
    hotelService.insertHotel(hotelDTO);
    return ResultVO.ok();
    }

    @ApiOperation(value = "添加房间产品功能")
    @PostMapping("add1")
    public ResultVO insertRoom(@RequestBody RoomDTO roomDTO){
        hotelService.insertRoom(roomDTO);
        return ResultVO.ok();
    }
    @ApiOperation(value = "修改酒店产品功能")
    @PostMapping("update")
    public ResultVO updateById(@RequestBody HotelDTO hotelDTO){
       hotelService.updateById(hotelDTO);
        return ResultVO.ok();
    }

    @ApiOperation(value = "修改房间产品功能")
    @PostMapping("update1")
    public ResultVO updateRoom(@RequestBody RoomDTO roomDTO){
       hotelService.updateRoom(roomDTO);
       return ResultVO.ok();
    }
    @ApiOperation(value = "删除酒店产品功能")
    @PostMapping("/{id}/delete")
    public ResultVO deleteHotelById( @PathVariable Long id){
        hotelService.deleteHotelById(id);
        return ResultVO.ok();
    }
    @ApiOperation(value = "删除房间产品功能")
    @PostMapping("/{id}/deleteRoom")
    public ResultVO deleteById( @PathVariable Long id){
//        int userId = (int) request.getAttribute("userId");
//        if(product.getUserId() != userId){
//            // 用户不具有删除此产品的权限
//            return new  ResultVO(StatusCode.FORBIDDEN_ERROR);
//        }
            hotelService.deleteById(id);
            return ResultVO.ok();
    }

    @ApiOperation(value = "查询酒店产品功能")
    @GetMapping("/{id}/select")
    public ResultVO selectHotel(@PathVariable Long id){
        HotelVO hotelVO= hotelService.selectHotel(id);
        if (hotelVO==null){
            return new ResultVO(StatusCode.OPERATION_FAILED);
        }
        return ResultVO.ok(hotelVO);
    }

    @ApiOperation(value = "查询房间产品功能")
    @GetMapping("/{id}/selectRoom")
    public ResultVO selectRoom(@PathVariable Long id){
        RoomVO roomVO = hotelService.selectRoom(id);
        if (roomVO==null){
            return new ResultVO(StatusCode.OPERATION_FAILED);
        }
            return ResultVO.ok(roomVO);
    }

}

